package com.mj.mybatis;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Map;

/**
 * @author 马洁
 * @date 2020/9/18 - 11:17
 */
public class MySqlSessionFactoryImpl implements MySqlSessionFactory {
    private DataSource dataSource;
    private Map<String, SqlBean> mapper;

    public MySqlSessionFactoryImpl(DataSource dataSource, Map<String, SqlBean> mapper) {
        this.dataSource = dataSource;
        this.mapper = mapper;
    }

    @Override
    public MySqlSession openSession() {
        try {
            return new MySqlSessionImpl(dataSource.getConnection(), mapper);
        } catch (SQLException throwables) {
            System.out.println("创建连接失败");
            throwables.printStackTrace();
        }

        return null;
    }

    @Override
    public DataSource getDataSource() {
        return dataSource;
    }
}
